package com.example.demo;

import com.example.demo.entity.COrder;
import com.example.demo.repository.COrderRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.Date;

@SpringBootApplication
public class DemoApplication {

    private static final Logger logger = LoggerFactory.getLogger(DemoApplication.class);

    @Autowired
    private COrderRepository cOrderRepository;

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner() {
        return new CommandLineRunner() {
            @Override
            public void run(String... args) throws Exception {

                logger.info("Hello Sharding-JDBC!");

                //添加数据
                COrder cOrder0 = new COrder();
                cOrder0.setDel(Boolean.FALSE); cOrder0.setUserId(0); cOrder0.setCompanyId(00); cOrder0.setPublishUserId(00);
                cOrder0.setPositionId(00); cOrder0.setResumeType(0); cOrder0.setStatus("WAIT");
                cOrder0.setCreateTime(new Date()); cOrder0.setUpdateTime(new Date());

                COrder cOrder0Saved = cOrderRepository.save(cOrder0);
                logger.info("添加数据 id:{} userId:{}", cOrder0Saved.getId(), cOrder0Saved.getUserId());

                COrder cOrder1 = new COrder();
                cOrder1.setDel(Boolean.FALSE); cOrder1.setUserId(1); cOrder1.setCompanyId(00); cOrder1.setPublishUserId(00);
                cOrder1.setPositionId(00); cOrder1.setResumeType(0); cOrder1.setStatus("AUTO_FILTER");
                cOrder1.setCreateTime(new Date()); cOrder1.setUpdateTime(new Date());

                COrder cOrder1Saved = cOrderRepository.save(cOrder1);
                logger.info("添加数据 id:{} userId:{}", cOrder1Saved.getId(), cOrder1Saved.getUserId());

                COrder cOrder2 = new COrder();
                cOrder2.setDel(Boolean.FALSE); cOrder2.setUserId(2); cOrder2.setCompanyId(00); cOrder2.setPublishUserId(00);
                cOrder2.setPositionId(00); cOrder2.setResumeType(0); cOrder2.setStatus("PREPARE_CONTACT");
                cOrder2.setCreateTime(new Date()); cOrder2.setUpdateTime(new Date());

                COrder cOrder2Saved = cOrderRepository.save(cOrder2);
                logger.info("添加数据 id:{} userId:{}", cOrder2Saved.getId(), cOrder2Saved.getUserId());

                COrder cOrder3 = new COrder();
                cOrder3.setDel(Boolean.FALSE); cOrder3.setUserId(3); cOrder3.setCompanyId(00); cOrder3.setPublishUserId(00);
                cOrder3.setPositionId(00); cOrder3.setResumeType(0); cOrder3.setStatus("REFUSE");
                cOrder3.setCreateTime(new Date()); cOrder3.setUpdateTime(new Date());

                COrder cOrder3Saved = cOrderRepository.save(cOrder3);
                logger.info("添加数据 id:{} userId:{}", cOrder3Saved.getId(), cOrder3Saved.getUserId());

                COrder cOrder4 = new COrder();
                cOrder4.setDel(Boolean.FALSE); cOrder4.setUserId(4); cOrder4.setCompanyId(00); cOrder4.setPublishUserId(00);
                cOrder4.setPositionId(00); cOrder4.setResumeType(0); cOrder4.setStatus("ARRANGE_INTERVIEW");
                cOrder4.setCreateTime(new Date()); cOrder4.setUpdateTime(new Date());

                COrder cOrder4Saved = cOrderRepository.save(cOrder4);
                logger.info("添加数据 id:{} userId:{}", cOrder4Saved.getId(), cOrder4Saved.getUserId());

                Thread.sleep(1000);

                //查询数据
                COrder cOrder0ByUserId = cOrderRepository.findByUserId(0);
                logger.info("查询数据 id:{} userId:{}", cOrder0ByUserId.getId(), cOrder0ByUserId.getUserId());

                COrder cOrder1ByUserId = cOrderRepository.findByUserId(1);
                logger.info("查询数据 id:{} userId:{}", cOrder1ByUserId.getId(), cOrder1ByUserId.getUserId());

                COrder cOrder2ByUserId = cOrderRepository.findByUserId(2);
                logger.info("查询数据 id:{} userId:{}", cOrder2ByUserId.getId(), cOrder2ByUserId.getUserId());

                COrder cOrder3ByUserId = cOrderRepository.findByUserId(3);
                logger.info("查询数据 id:{} userId:{}", cOrder3ByUserId.getId(), cOrder3ByUserId.getUserId());

                COrder cOrder4ByUserId = cOrderRepository.findByUserId(4);
                logger.info("查询数据 id:{} userId:{}", cOrder4ByUserId.getId(), cOrder4ByUserId.getUserId());
            }
        };
    }

}
